package test0102.ecommercePlatform;

public class Platform {
    private String name;
    private static Order[] orders = new Order[10];
    private static int orderCount = 0;
    public Platform() {

    }

    public Platform(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Platform{" +
                "name='" + name + '\'' +
                '}';
    }


    public void add(Order order) {
        for(int i=0; i<orders.length; i++){
            if(orders[i]==null){
                orders[i] = order;
                orderCount++;
                break;
            }
        }
    }


    public void printAll() {
        for(int i=0; i<orders.length; i++){
            if(orders[i]!=null){
                System.out.println(orders[i]);
            }
        }
    }

    public Order findMaxOrder() {
        Order maxOrder = orders[0];
        for(int i=0; i<orders.length; i++){
            if(orders[i]!=null){
                if(orders[i].getAmount()>maxOrder.getAmount()){
                    maxOrder = orders[i];
                }
            }
        }
        return maxOrder;
    }

    public Order findMinOrder() {
        Order minOrder = orders[0];
        for(int i=0; i<orders.length; i++){
            if(orders[i]!=null){
                if(orders[i].getAmount()<minOrder.getAmount()){
                    minOrder = orders[i];
                }
            }
        }
        return minOrder;
    }

    public Order findOrderByName(String name) {
        Order aabbcc = null;
        for(int i=0; i<orders.length; i++){
            if(orders[i]!=null){
                if(orders[i].getCustomerName().equals(name)){
                    aabbcc = orders[i];
                    break;
                }
            }
        }
        return aabbcc;
    }

    public double calculateAverage() {
        int count = 0;
        for(int i=0; i<orders.length; i++){
            if(orders[i]!=null){
                count += orders[i].getAmount();
            }
        }
        return count / orderCount;
    }
}
